package com.china08.yxyapi.rabbitmq.listener.statistics;

import java.text.ParseException;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.china08.yxyapi.config.RabbitConfig;
import com.china08.yxyapi.service.res.statistics.impl.ResourceStatisticsEsImpl;
import com.china08.yxyapi.util.DateUtils;

/**
 * 备授课系统,pv统计,采纳了统计
 *
 */
@Component
@EnableRabbit
public class ResourceReportEsListener {

    public static final Logger LOGGER = LoggerFactory.getLogger(ResourceReportEsListener.class);

    @Autowired
    private ResourceStatisticsEsImpl resourceStatisticsEsImpl;

    /**
     * @param date
     *            统计资源, 学校资源的总数es
     */
    @RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_ES)
    private void schoolStatisticsTotalEs(Integer date) {
        resourceStatisticsEsImpl.schoolStatisticsTotalEs(date);
    }

    /**
     * 统计资源，学校每天资源的总数es
     * 
     * @throws ParseException
     */
    @RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_DAY_ES)
    private void ywStatisticsResourceAreaForDayEs(Integer date) throws ParseException {
        String startDate = DateUtils.formatDate8(DateUtils.getFirstDay(DateUtils.getBeforeDay(new Date())));
        String endDate = DateUtils.formatDate8(DateUtils.getFirstDay(DateUtils.getTimesnight(new Date())));
        Integer beforeDate = DateUtils.formatDate4(DateUtils.getFirstDay(DateUtils.getBeforeDay(new Date())));
        resourceStatisticsEsImpl.ywStatisticsResourceAreaForDayEs(startDate, endDate, beforeDate);
    }

    /**
     * 统计用户资源，用户资源的总数
     * 
     * @throws ParseException
     */

    @RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_USER_ES)
    private void userSchoolStatistics(Integer date) throws ParseException {
        resourceStatisticsEsImpl.userSchoolStatistics(date);
    }

    /**
     * 统计用户资源，用户每天资源的总数
     * 
     * @throws ParseException
     */

    @RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_USER_DAY_ES)
    private void ywStatisticsResourceSchoolEs(Integer date) throws ParseException {
        String startDate = DateUtils.formatDate8(DateUtils.getFirstDay(DateUtils.getBeforeDay(new Date())));
        String endDate = DateUtils.formatDate8(DateUtils.getFirstDay(DateUtils.getTimesnight(new Date())));
        Integer beforeDate = DateUtils.formatDate4(DateUtils.getFirstDay(DateUtils.getBeforeDay(new Date())));
        resourceStatisticsEsImpl.ywStatisticsResourceSchoolEs(startDate, endDate, beforeDate);
    }

    /********************************* 新修改 ***************************************/
    /**
     * @param date
     *            统计资源, 学校资源的总数es
     */
    @RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_NEW_ES)
    private void statisticsResourceSchoolNewEs(Integer date) {
        resourceStatisticsEsImpl.schoolStatisticsTotalNewEs(date);
    }

    /**
     * @param date
     *            统计资源, 学校资源每天总数es
     * @throws ParseException
     */
    @RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_USER_DAY_NEW_ES)
    private void statisticsResourceUserSchoolDayNewEs(Integer beforeDate) throws ParseException {

        Date aDate = DateUtils.formatStrDate4(beforeDate);

        String startDate = DateUtils.formatDate8(DateUtils.getFirstDay(aDate));
        String endDate = DateUtils.formatDate8(DateUtils.getTimesnight(aDate));
        // Integer beforeDate1 =
        // DateUtils.formatDate4(DateUtils.getFirstDay(DateUtils.getBeforeDay(aDate)));

        LOGGER.info("资源学校跑数据_进监听" + startDate + endDate + beforeDate);
        resourceStatisticsEsImpl.ywStatisticsResourceSchoolNewEs(startDate, endDate, beforeDate);
    }

    /**
     * 统计资源，学校每天资源的总数es
     * 
     * @throws ParseException
     */
    @RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_DAY_NEW_ES)
    private void ywStatisticsResourceSchoolDayNewEs(Integer beforeDate) throws ParseException {
        Date aDate = DateUtils.formatStrDate4(beforeDate);
        String startDate = DateUtils.formatDate8(DateUtils.getFirstDay(aDate));
        String endDate = DateUtils.formatDate8(DateUtils.getTimesnight(aDate));
        resourceStatisticsEsImpl.ywStatisticsResourceAreaForDayNewEs(startDate, endDate, beforeDate);
    }

}
